<template>
  <!-- 技术-技术月报=双优化未实施情况 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData :searchData="searchArr" @search="search"></searchData>
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title"></title-name> -->
      <!-- 表格 -->
      <list-table
        ref="table"
        tableLayout="fixed"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :page-keys="['pageNo', 'pageSize','totalSize']"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template slot="action" slot-scope="text, record">
          <a v-btnPermission="'tm_034_loo_04'" @click="handleManage(0, record)">查看</a>
          <span v-btnPermission="'tm_034_tyy_01'">
            <a-divider type="vertical" />
            <a @click="handleManage(1, record)">填写原因</a>
          </span>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getOptimizedConditionsList } from '@/api/technical/OptimizedConditions' // api
import BasePage from '@/views/basePage' // 基础配置
import SelectProject from '@/components/Select/SelectProject' // 项目
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司s
import OrgTreeSelect from '@/components/OrgTreeSelect'
import Item from '@/components/AvatarList/Item.vue'
const searchArr = [
  // 搜索框
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  { name: '方案名称', type: 'input', value: 'name' },
  { name: '填报人', type: 'input', value: 'creatorName' },
  {
    name: '填报时间',
    type: 'dateRange',
    value: 'createTime',
    attr: {
      rangeFormat: ['createTimeBegin', 'createTimeEnd']
    }
  }
]

const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  { title: '月份', dataIndex: 'monthStr', width: '80px'},
  { title: '所属分公司', dataIndex: 'branchComName' },
  { title: '所属项目', dataIndex: 'projectName', ellipsis: true },
  { title: '双优化名称', dataIndex: 'name', ellipsis: true },
  { title: '立项通过时间', dataIndex: 'passDate' },
  { title: '未实施原因或实施与立项内容不符原因', dataIndex: 'content', width: '300px', ellipsis: true },
  { title: '填报人', dataIndex: 'creatorName', ellipsis: true },
  { title: '填报时间', dataIndex: 'createTime' },
  { title: '操作', dataIndex: 'action', width: '180px', align: 'center', scopedSlots: { customRender: 'action' } }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    Item,
    SelectSubCompany,
    SelectProject
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      loadData: async parameter => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        return getOptimizedConditionsList(requestParameters).then(res => {
          return res
        })
      }
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateOptimizedConditions',
        query
      })
    }
  },
  created() {}
}
</script>
